class Seiso::ImportMaster
  # Imports a service document into Seiso.
  #
  # Author:: Willie Wheeler
  # Author:: Ian McCunn
  # Copyright:: Copyright (c) 2014-2016 Expedia, Inc.
  # License:: Apache 2.0
  class Importers::ServiceImporter < Importers::BaseImporter

    def initialize(api, rest_util, resolver)
      self.api = api
      self.rest_util = rest_util
      self.mapper = Mappers::ServiceMapper.new resolver
      self.repo_resource = api.services.get

      @validator = Validators::ServiceValidator.new
      @search_resource = repo_resource.search.get
    end

    def import(doc)
      @validator.validate doc
      import_items(doc['items'], {})
    end

    # Can't make these protected, because that prevents BaseImporter from seeing them.
#    protected

    # BaseImporter callback
    def to_search_params(doc_service, context)
      { 'key' => doc_service['key'] }
    end

    # BaseImporter callback
    def find_resource(search_params)
      @search_resource.findByKey(key: search_params['key']).get
    end
  end
end
